<#assign basePath=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改用户</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <#include '/common/common-css.html'>
</head>

<body>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="myForm">
                        <input type="hidden" name="id" id="id">
                        <input type="hidden" name="orgName" id="orgName">
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>机构名称：</label>
                            <div class="col-sm-8">
                                 <select class="form-control m-b" name="orgId" id="orgId">
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>用户名：</label>
                            <div class="col-sm-8">
                                <input id="username" name="username" class="form-control" type="text">
                                <span class="help-block m-b-none">
                                	<!-- <i class="fa fa-info-circle"></i> 这里写点提示的内容 -->
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>真实姓名：</label>
                            <div class="col-sm-8">
                                <input id="realname" name="realname" class="form-control" type="text">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>新密码：</label>
                            <div class="col-sm-8">
                                <input id="password" name="password" class="form-control" type="password">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>确认密码：</label>
                            <div class="col-sm-8">
                                <input id="repassword" name="repassword" class="form-control" type="password">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
              
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <#include '/common/common-js.html'>
    <script type="text/javascript">
    $().ready(function() {
    	
    	if('' != "${u}"){
    		//组织机构回显
    		$.ajax({    
    	        type: "post",   
    	        url: "${ basePath }/org/tree?t=" + Math.random(),   
    	        dataType: "json",    
    	        success: function (data) { 
    	        	if(data.error){
						layer.msg(data.msg,{icon:2,time:1000});
					}else{
						$(data).each(function(){
	    	        		var orgName = this.name;
	    	        		orgName = orgName.substring(orgName.lastIndexOf('>') + 2);
	    	        		$("#orgId").append("<option value="+ this.id +">"+ orgName +"</option>");
	    	        		$("#orgId").val("${u.orgId}");
	    	        	});
					}
    	        },
    	        error : function(e){
    	        	console.log(e);
    	        }
    	    });
    		
    		$("#id").val("${u.id}");
    	    $("#orgName").val("${u.orgName}");
    		$("#username").val("${u.username}");
    		$("#realname").val("${u.realname}");
    	}
    	
	    
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#myForm").validate({
            rules: {
                username: {
                	"required" : !0,
                	minlength : 1,
                	maxlength : 10
                },
                realname : {
                    required: !0,
                    minlength: 1
                },
                password : {
                    required: !0,
                    minlength: 5
                },
                repassword : {
                    required: !0,
                    minlength: 5,
                    equalTo: "#password"
                }
            },
            messages: {
                username: {
                	required: e + "请输入您的用户名",
                    minlength: e + "用户名必须1个字符以上",
                    maxlength : e + "长度不能超过10个字符"
                },
                realname : {
                	required: e + "请输入真实姓名",
                    minlength: e + "长度最少为1个字符"
                },
                password : {
                    required: e + "请输入密码",
                    minlength: e + "长度最少为5个字符"
                },
                repassword : {
                    required: e + "请输入重复密码",
                    minlength: e + "长度最少为5个字符",
                    equalTo: e + "两次输入的密码不一致"
                }
            },
            submitHandler:function(form){
            	var orgId = $("#orgId").val();
            	var text = $("#orgId").find("option[value='"+ orgId +"']").text();
            	$("#orgName").val(text);
            	
            	var data = {
            		"id" : $("#id").val(),
            		"username" : $("#username").val(),
            		"realname" : $("#realname").val(),
            		"password" : $("#password").val(),
            		"orgId" : $("#orgId").val(),
            		"orgName" : $("#orgName").val()
            	};
    			$.ajax({    
    		        type: "post",   
    		        url: "${ basePath }/user/add?t=" + Math.random(),   
    		        data : data,
    		        dataType: "json",    
    		        success: function (data) { 
    		        	if(data != null){
    		        		parent.table.ajax.reload();
    		            	var index = parent.layer.getFrameIndex(window.name);
    		        		parent.layer.close(index);
    		        	}
    		        }    
    		    }) 
    		}
        }); 
        
        /* $("#myForm").validate({
            rules: {
                firstname: "required",
                lastname: "required",
                username: {
                    required: !0,
                    minlength: 2
                },
                password: {
                    required: !0,
                    minlength: 5
                },
                confirm_password: {
                    required: !0,
                    minlength: 5,
                    equalTo: "#password"
                },
                email: {
                    required: !0,
                    email: !0
                },
                topic: {
                    required: "#newsletter:checked",
                    minlength: 2
                },
                agree: "required"
            },
            messages: {
                firstname: e + "请输入你的姓",
                lastname: e + "请输入您的名字",
                username: {
                    required: e + "请输入您的用户名",
                    minlength: e + "用户名必须两个字符以上"
                },
                password: {
                    required: e + "请输入您的密码",
                    minlength: e + "密码必须5个字符以上"
                },
                confirm_password: {
                    required: e + "请再次输入密码",
                    minlength: e + "密码必须5个字符以上",
                    equalTo: e + "两次输入的密码不一致"
                },
                email: e + "请输入您的E-mail",
                agree: {
                    required: e + "必须同意协议后才能注册",
                    element: "#agree-error"
                }
            }
        }); */
    });
    </script>
</body>
</html>


    